package com.jic.product.controller.manage;


import com.jic.common.base.vo.RestResult;
import com.jic.product.model.vo.request.ParameterJsonRequest;
import com.jic.product.model.vo.request.ParameterJsonUpdateRequest;
import com.jic.product.model.vo.request.ProductParameterAddRequest;
import com.jic.product.model.vo.response.ParameterJsonResponse;
import com.jic.product.model.vo.response.ProductParameterListResponse;
import com.jic.product.service.ProductParameterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by LD on 2020/10/4 19:04
 * 商品参数
 */
@RestController
@RequestMapping("/productParameter")
@Api(value = "商品参数", tags = "商品参数")
@Slf4j
public class ProductParameterController {

    @Autowired
    private ProductParameterService productParameterService;

    @ApiOperation(value = "根据分类编号查询所有参数")
    @GetMapping(value = "/listAll")
    public RestResult<List<ProductParameterListResponse>> queryPage(Long categoryId) {
        return RestResult.success(productParameterService.listAll(categoryId));

    }

    @ApiOperation(value = "新增商品参数")
    @PostMapping(value = "/add")
    public RestResult<Long> add(@RequestBody ProductParameterAddRequest addRequest) {
        return RestResult.success(productParameterService.add(addRequest));
    }

    @ApiOperation(value = "新增商品参数")
    @PostMapping(value = "/delete/{id}")
    public RestResult<String> delete(@PathVariable Long id) {
        int f = productParameterService.delete(id);
        if(f>0){
            return RestResult.success("删除成功");
        }
        return RestResult.error("9999","删除失败");
    }

    @ApiOperation(value = "获取商品参数json")
    @PostMapping(value = "/getParameterJson")
    public RestResult<ParameterJsonResponse> getParameterJson(@RequestBody ParameterJsonRequest request) {
        return RestResult.success(productParameterService.getParameterJson(request));

    }

    @ApiOperation(value = "修改商品参数json")
    @PostMapping(value = "/updateParameterJson")
    public RestResult<Integer> updateParameterJson(@RequestBody ParameterJsonUpdateRequest request) {
        return RestResult.success(productParameterService.updateParameterJson(request));

    }
}
